package com.pingan.agentbank.aaos.testme;

import com.alibaba.fastjson.JSON;
import com.pingan.agentbank.aaos.Start;
import com.pingan.agentbank.aaos.pojo.ApproLineInfo;
import com.pingan.agentbank.aaos.pojo.BusiData;
import com.pingan.agentbank.aaos.pojo.RequestInfo;
import com.pingan.agentbank.aaos.pojo.SysHeader;
import com.pingan.agentbank.aaos.util.AaisRemote;
import com.pingan.vframe.Controller;
import com.pingan.vframe.beans.Injector;
import com.pingan.vframe.sdo.ServiceData;
import com.pingan.vframe.util.BeanView;
import org.junit.Test;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

public class ScriptTest {

    /*
     * 生成文件脚本
     * */
    @Test
    public void method1() {
        String string = "{\"party_no\":\"9537\",\"expand_branch\":\"\",\"chinese_name\":\"李小明\",\"sex\":\"M\",\"birth_date\":\"19911125\",\"owner_name\":\"lixiaoming\",\"mobile\":\"15738885696\",\"email\":\"163@qq.com\",\"country_citizen\":\"\",\"global_type\":\"1\",\"global_id\":\"410823199111070000\",\"global_eff_enddate\":\"20271115\",\"global_eff_flag\":\"\",\"issuing_authority\":\"\",\"marital_status\":\"1\",\"children_flag\":\"1\",\"education\":\"02\",\"phone_area\":\"0371\",\"home_phome\":\"7683791\",\"address1\":\"城市经典玉树\",\"address2\":\"城市经典玉树\",\"address3\":\"城市经典玉树\",\"address4\":\"城市经典玉树\",\"postcode\":\"454950\",\"residential_type\":\"1\",\"companyname\":\"住建局\",\"departname\":\"审计科\",\"post\":\"科长\",\"employer_add1\":\"上海市黄浦路111号\",\"employer_add2\":\"上海市黄浦路111号\",\"employer_add3\":\"上海市黄浦路111号\",\"employer_add4\":\"上海市黄浦路111号\",\"employer_postcode\":\"454950\",\"employer_phone_areano\":\"0371\",\"employer_phone\":\"7758258\",\"company_type\":\"01\",\"working_years\":\"20\",\"annual_income\":\"1000\",\"ex_working_years\":\"2\",\"immidediate_name\":\"王大明\",\"immidediate_relation\":\"2\",\"immidediate_mobile\":\"15738518183\",\"other_name\":\"周杰伦\",\"other_relation\":\"2\",\"other_mobile\":\"13782850669\",\"car_number\":\"\",\"car_brand\":\"\",\"bank_account\":\"123\",\"mainBillingPostType\":\"电子账单\",\"send_addr_type\":\"1\",\"salses_name\":\"王岐山\",\"sales_code\":\"001\",\"sales_company_code\":\"\",\"application_tool\":\"\",\"applytime\":\"\",\"upload_cardtye\":\"\",\"creditcardCategory\":\"信用卡\",\"creditcardType\":\"白金卡\",\"collection_no\":\"11111\",\"bar_code\":\"123456\",\"swimmingGold\":\"0.50\",\"source_code\":\"\",\"affinityCode\":\"中国人民银行\",\"applicationFlag\":\"0\",\"positionname\":\"大领导\",\"referrer_globalid\":\"\",\"referrer_mobile\":\"\",\"channel_id\":\"0\",\"expand_source\":\"\",\"monthly_mortgage_payment\":\"\",\"payment_limit_type\":\"\",\"campaign_code\":\"\",\"giveCardCity\":\"上海\",\"referrer_name\":\"\",\"expand_no\":\"\",\"agentunit\":\"UCCB\",\"reside_years\":\"50\",\"reside_add1\":\"张江以南\",\"reside_add2\":\"张江以南\",\"reside_add3\":\"张江以南\",\"reside_add4\":\"张江以南\",\"reside_postcode\":\"9999\",\"job_code\":\"023\",\"job_description\":\"032\",\"certification_type\":\"中国税收居民\",\"isOwnerMobile\":\"1\",\"ownerMobileStatus\":\"2\",\"useTimeScore\":\"2\",\"audit_result\":\"通过\",\"amount\":\"1000\",\"refuse_code\":\"\"}\n";
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < 1; i++) {
            sb.append(string);
        }

        for (int i = 0; i < 1; i++) {

            String fileName = "D:\\temp\\ZJKB\\sourDir\\ZJKB-APPROVAL-20190121-12"+i;
            OutputStream outputStream = null;
            try {
                outputStream = new FileOutputStream(fileName + ".txt");
                outputStream.write(sb.toString().getBytes());
                outputStream.flush();
                outputStream.close();

                File file = new File(fileName + ".ok");
                file.createNewFile();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }


    /*
     * 生成文件脚本--分库
     * */
    @Test
    public void method3() {

        String org = "WRCB";
        String[] strings = org.split(",");


        String string = "{\"application_no\":\"6a2292c4-790c-4a39-9094-140a7ea23aa8\",\"party_no\":\"9537\",\"expand_branch\":\"\",\"chinese_name\":\"李小明\",\"sex\":\"M\",\"birth_date\":\"19911125\",\"owner_name\":\"lixiaoming\",\"mobile\":\"15738885696\",\"email\":\"\",\"country_citizen\":\"\",\"global_type\":\"1\",\"global_id\":\"410823199111070000\",\"global_eff_enddate\":\"20271115\",\"global_eff_flag\":\"\",\"issuing_authority\":\"\",\"marital_status\":\"1\",\"children_flag\":\"1\",\"education\":\"02\",\"phone_area\":\"0371\",\"home_phome\":\"7683791\",\"address1\":\"城市经典玉树\",\"address2\":\"城市经典玉树\",\"address3\":\"城市经典玉树\",\"address4\":\"城市经典玉树\",\"postcode\":\"454950\",\"residential_type\":\"1\",\"companyname\":\"住建局\",\"departname\":\"审计科\",\"post\":\"科长\",\"employer_add1\":\"上海市黄浦路111号\",\"employer_add2\":\"上海市黄浦路111号\",\"employer_add3\":\"上海市黄浦路111号\",\"employer_add4\":\"上海市黄浦路111号\",\"employer_postcode\":\"454950\",\"employer_phone_areano\":\"0371\",\"employer_phone\":\"7758258\",\"company_type\":\"01\",\"working_years\":\"20\",\"annual_income\":\"1000\",\"ex_working_years\":\"2\",\"immidediate_name\":\"王大明\",\"immidediate_relation\":\"2\",\"immidediate_mobile\":\"15738518183\",\"other_name\":\"周杰伦\",\"other_relation\":\"2\",\"other_mobile\":\"13782850669\",\"car_number\":\"\",\"car_brand\":\"\",\"bank_account\":\"123\",\"mainBillingPostType\":\"电子账单\",\"send_addr_type\":\"1\",\"salses_name\":\"王岐山\",\"sales_code\":\"001\",\"sales_company_code\":\"\",\"application_tool\":\"\",\"applytime\":\"\",\"upload_cardtye\":\"\",\"creditcardCategory\":\"信用卡\",\"creditcardType\":\"白金卡\",\"collection_no\":\"11111\",\"bar_code\":\"123456\",\"swimmingGold\":\"0.50\",\"source_code\":\"\",\"affinityCode\":\"中国人民银行\",\"applicationFlag\":\"0\",\"positionname\":\"经理\",\"referrer_globalid\":\"\",\"referrer_mobile\":\"\",\"channel_id\":\"0\",\"expand_source\":\"\",\"monthly_mortgage_payment\":\"\",\"payment_limit_type\":\"\",\"campaign_code\":\"\",\"giveCardCity\":\"上海\",\"referrer_name\":\"\",\"expand_no\":\"\",\"agentunit\":\"UCCB\",\"reside_years\":\"50\",\"reside_add1\":\"张江以南\",\"reside_add2\":\"张江以南\",\"reside_add3\":\"张江以南\",\"reside_add4\":\"张江以南\",\"reside_postcode\":\"9999\",\"job_code\":\"023\",\"job_description\":\"032\",\"certification_type\":\"中国税收居民\",\"isOwnerMobile\":\"1\",\"ownerMobileStatus\":\"2\",\"useTimeScore\":\"2\",\"audit_result\":\"通过\",\"amount\":\"1000\",\"refuse_code\":\"\"}\n";
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < 10; i++) {
            sb.append(string);
        }

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd-");
        String date = simpleDateFormat.format(new Date());

        for (String orgStr:strings){

            for (int i = 0; i < 10; i++) {

                String fileName = "D:\\temp\\"+orgStr+"\\sourDir\\"+"RS-"+orgStr+"-APPROVAL-"+date+i;
                OutputStream outputStream = null;
                try {
                    outputStream = new FileOutputStream(fileName + ".txt");
                    outputStream.write(sb.toString().getBytes());
                    outputStream.flush();
                    outputStream.close();

                    File file = new File(fileName + ".ok");
                    file.createNewFile();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }



    }

    @Test
    public void method2(){

        File file = new File("D:\\Mine\\code\\aaos\\applib");

        String pre = "/usr/local/app/aaosWeb/app/";
        String[] strings = file.list();
        StringBuffer sb = new StringBuffer();
        for (String str:strings) {
            str = pre+str+";";
            sb.append(str);

        }

        System.out.println(sb.toString());
    }

    @Test
    public void method4(){
        String org = "UCCB,ZJKB";
        String[] strings = org.split(",");
        for (String s:strings){
            System.out.println(s);
        }
    }

    @Test
    public void method5(){
        String s = "\"sysHeader\": {\n" +
                "\t\t\t\t\t\"orgCode\": \"BOJY\"\n" +
                "\t\t\t\t}";

        String aa= "\"asdfasd\"";

        String bb = "{\"responseCode\":\"000000\",\"responseMsg\":\"success\",\"sysHeader\":\"\",\"busiData\":{\"collection_no\":\"\",\"chinese_name\":\"tom\",\"global_id\":\"110\",\"residential_type\":\"1\",\"test\":\"yes\"}}";

        String s1 = "{\"applyNum\": \"37ec10ee-7484-4b3b-8dbb-982afdce4339\",\"queryPara\": [\"collection_no\", \"chinese_name\", \"global_id\", \"residential_type\", \"test\"],\"queryType\": 0}";
    }

    @Test
    public void method6(){
        /*String appId = "04";
        String orgCode = "BOJY";
        SysHeader sysHeader = new SysHeader(String.valueOf(new Date().getTime()), appId, UUID.randomUUID().toString().replace("-", ""), orgCode);*/
        SysHeader sysHeader = new SysHeader();
        sysHeader.setOrgCode("BOJY");


        String queryType = "0";
        List<String> queryPara = new ArrayList<>();
        queryPara.add("collection_no");
        queryPara.add("chinese_name");
        queryPara.add("global_id");
        queryPara.add("test");
        queryPara.add("residential_type");

        BusiData busiData = new BusiData(queryType, "37ec10ee-7484-4b3b-8dbb-982afdce4339", queryPara);

        RequestInfo requestInfoNew = new RequestInfo(sysHeader, busiData);
        String json = JSON.toJSONString(requestInfoNew);
        System.out.println(json);

        Injector injector = Controller.getInstance().getInjector();
        AaisRemote aaisRemote = injector.getBean(AaisRemote.class);
        ServiceData serviceData = aaisRemote.getApplyInfoFromAAIS(requestInfoNew);
        String responseCode = serviceData.getString("responseCode");
        System.out.println(responseCode);

    }

    @Test
    public void method7(){
        System.out.println("--start--");
        throw new RuntimeException("运算异常");
        //System.out.println(10/0);
        //System.out.println("--over--");

    }

    @Test
    public void method8(){

        System.out.println("--start--");
        ApproLineInfo approLineInfo = new ApproLineInfo();
        String product_id = "";
        if ("C".equals(approLineInfo.getCreditcardtype())&&"G".equals(approLineInfo.getCreditcardcategory())&&"0000".equals(approLineInfo.getAffinitycode())){
            product_id = "000041";
        } else if ("C".equals(approLineInfo.getCreditcardtype())&&"C".equals(approLineInfo.getCreditcardcategory())&&"0000".equals(approLineInfo.getAffinitycode())){
            product_id = "000040";
        }

    }

    public static void main(String[] args) {

        MyThread myThread = new MyThread();
        try {
            myThread.run();
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    @Test
    public void method9(){
        System.err.println("111");
        ApproLineInfo approLineInfo = new ApproLineInfo();
        approLineInfo.setId(1);
        approLineInfo.setFile_id(2);
        BeanView.getFieldView(approLineInfo);
    }
}
